
CROSS_COMPILE = 
AS		= $(CROSS_COMPILE)as
LD		= $(CROSS_COMPILE)ld
CC		= $(CROSS_COMPILE)gcc
CPP		= $(CC) -E
AR		= $(CROSS_COMPILE)ar
NM		= $(CROSS_COMPILE)nm

STRIP		= $(CROSS_COMPILE)strip
OBJCOPY		= $(CROSS_COMPILE)objcopy
OBJDUMP		= $(CROSS_COMPILE)objdump

export AS LD CC CPP AR NM
export STRIP OBJCOPY OBJDUMP

CFLAGS := -Wall -O2 -g
CFLAGS += -I $(shell pwd)/include

LDFLAGS := 

export CFLAGS LDFLAGS

TOPDIR := $(shell pwd)
export TOPDIR

TARGET := test


obj-y += main.o
obj-y += sub.o
obj-y += a/

#1.一般都是从all开始，可以看出，首先有一个依赖start_recursive_build，然后先跳到下面执行start_recursive_build这个目标
all : start_recursive_build $(TARGET)
	@echo $(TARGET) has been built!

#2.start_recursive_build进入当前目录，使用Makefile.build来编译当前目录（处理顶层目录）
start_recursive_build:
	make -C ./ -f $(TOPDIR)/Makefile.build

$(TARGET) : built-in.o
	$(CC) -o $(TARGET) built-in.o $(LDFLAGS)

clean:
	rm -f $(shell find -name "*.o")
	rm -f $(TARGET)

distclean:
	rm -f $(shell find -name "*.o")
	rm -f $(shell find -name "*.d")
	rm -f $(TARGET)


#root@Iron2222:/home/book/vscode_ws/makefile/05_general_Makefile/example# make**指定make
#make -C ./ -f /home/book/vscode_ws/makefile/05_general_Makefile/example/Makefile.build
#make[1]: Entering directory '/home/book/vscode_ws/makefile/05_general_Makefile/example'
#make -C a -f /home/book/vscode_ws/makefile/05_general_Makefile/example/Makefile.build
#make[2]: Entering directory '/home/book/vscode_ws/makefile/05_general_Makefile/example/a'**进入a目录下，然后执行生成.o文件，然后链接生成built_in.o文件
#gcc -Wall -O2 -g -I /home/book/vscode_ws/makefile/05_general_Makefile/example/include -D DEBUG  -Wp,-MD,.sub2.o.d -c -o sub2.o sub2.c
#gcc -Wall -O2 -g -I /home/book/vscode_ws/makefile/05_general_Makefile/example/include -D DEBUG -D DEBUG_SUB3 -Wp,-MD,.sub3.o.d -c -o sub3.o sub3.c
#ld -r -o built-in.o sub2.o sub3.o
#make[2]: Leaving directory '/home/book/vscode_ws/makefile/05_general_Makefile/example/a'**离开a目录下，然后进入顶层目录，执行生成.o和。。。上面一样
#gcc -Wall -O2 -g -I /home/book/vscode_ws/makefile/05_general_Makefile/example/include   -Wp,-MD,.main.o.d -c -o main.o main.c
#gcc -Wall -O2 -g -I /home/book/vscode_ws/makefile/05_general_Makefile/example/include   -Wp,-MD,.sub.o.d -c -o sub.o sub.c
#ld -r -o built-in.o main.o sub.o a/built-in.o**链接
#make[1]: Leaving directory '/home/book/vscode_ws/makefile/05_general_Makefile/example'**离开
#gcc -o test built-in.o **链接生成test 
#test has been built!

	